package com.msb.mall.product.web;

import com.msb.mall.product.entity.CategoryEntity;
import com.msb.mall.product.service.CategoryService;
import com.msb.mall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/","/index.html","/home","/home.html","/index"})
    public String index(Model model){
        // 获取一级分类
        List<CategoryEntity> categoryEntities = categoryService.getLeve1Catagory();
        model.addAttribute("categorys",categoryEntities);

        return "index";
    }

    /**
     * 获取二级三级分类
     * @return
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String,List<Catalog2Vo>> gerCatalog2Json(){
        Map<String,List<Catalog2Vo>> map = categoryService.getCatalog2Json();
        return map;
    }


}
